package p18.code;

import java.util.concurrent.*;

public class CancellingExecutor extends ThreadPoolExecutor {


    public CancellingExecutor(int corePoolSize, int maximumPoolSize, long keepAliveTime, TimeUnit unit, BlockingQueue<Runnable> workQueue) {
        super(corePoolSize, maximumPoolSize, keepAliveTime, unit, workQueue);
    }

    /**
     *
     * @param callable
     * @param <T>
     * @return
     */
    protected<T> RunnableFuture<T> newTaskFor(Callable<T> callable) {
        if(callable instanceof CancelableTask)
            return ((CancelableTask<T>)callable).newTask();//创建CancelTask自己的Future
        else
            return super.newTaskFor(callable);//否则创建一个默认的Future
    }

}
